package suzf.top.kotlinjava.common.security

import org.slf4j.LoggerFactory
import org.springframework.security.core.GrantedAuthority
import org.springframework.security.core.authority.SimpleGrantedAuthority
import org.springframework.security.core.userdetails.UserDetails
import suzf.top.kotlinjava.common.entity.User

/**
 *
 *========================
 * Created with IntelliJ IDEA
 * Author:Mr.Su
 * Date:2019/9/28
 * Time:12:25
 * ========================
 */
class DisableDefaultUserDetails(private val user: User) : UserDetails {

    private val logger = LoggerFactory.getLogger(DisableDefaultUserDetails::class.java)

    override fun getAuthorities(): MutableCollection<out GrantedAuthority> {
        logger.info("DisableDefaultUserDetails{}  getAuthorities ")
        return mutableListOf(SimpleGrantedAuthority("ROLE_USER"))
    }

    override fun getUsername(): String {
        return user.username as String
    }

    override fun getPassword(): String {
        return user.password as String
    }

    override fun isEnabled(): Boolean {
        logger.warn("------------- isEnabled {} ---------${user.ban}")
        return true
    }

    override fun isCredentialsNonExpired(): Boolean {
        return true
    }

    override fun isAccountNonExpired(): Boolean {
        return true
    }

    override fun isAccountNonLocked(): Boolean {
        return true
    }
}
